# -*- coding: utf-8 -*-
# article_all.py
# Created by Hardy on 24th, Jan
# Copyright 2017 杭州网川教育科技有限公司. All rights reserved.
from querier.esquerier import ElasticSearchQuerier
import logging
# from utils import INDUSTRY_NAME_DICT


logger = logging.getLogger()


class InfoQuerier(ElasticSearchQuerier):

    def __init__(self, es, kol_index_list):
        super(InfoQuerier, self).__init__(None, None, None)
        self.es = es
        self.kol_index_list = kol_index_list
        # self.industries = len(INDUSTRY_NAME_DICT)

    def search(self, args):
        total = 0
        socials = 0
        for item in self.kol_index_list:
            index = None
            doc_type = None
            try:
                index = item['index']
                doc_type = item['doc_type']
                res = self.es.count(index=index, doc_type=doc_type)
                total += res['count']
                socials += 1
            except Exception as ex:
                logger.error('failed to get count from index=%s doc_type=%s, error=%s' % (index, doc_type, ex))
        return {'infos': {
            'kol': {
                'sum': total,
                'socials': socials,
                # 'industries': self.industries
            }
        }}

    def _build_query(self, *args):
        pass

    def _build_result(self, es_result, param):
        pass